package com.service.impl;

import com.mapper.OrderProjectMapper;
import com.mapper.ReturnerMapper;
import com.pojo.OrderProject;
import com.pojo.Project;
import com.pojo.Returner;
import com.service.ProjectService;
import com.service.ReturnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ReturnerServiceImpl implements ReturnerService {
    @Autowired
    private ReturnerMapper returnerMapper;
    @Autowired
    private ProjectService projectService;

    @Override
    public List<Returner> selectReturnByprojectid(long projectId) {
        return returnerMapper.selectReturnByprojectid(projectId);
    }

    @Override
    public Returner selectByreturnid(long id) {
        return returnerMapper.selectByreturnid(id);
    }

    @Override
    public int insertReturner(Returner returner) {
        return returnerMapper.insertReturner(returner);
    }

    @Override
    public int updateReturnerCount(long id, long count) {
        return returnerMapper.updateReturnerCount(id,count);
    }

    @Override
    public int fangfa(long projectId) {
        /**
         * 总体思路
         * 1、根据项目id来获取项目
         * 2、根据项目名来获取所有订单
         * 3、遍历并删除相应订单
         * 4、根据项目名删除相应详情表
         * 5、删除回报表
         */
        Project project = projectService.selectProjectById(projectId);
        List<Returner> returners = returnerMapper.selectReturnByprojectid(projectId);
        List<OrderProject> orderProjects = returnerMapper.selectByProjectName(project.getProjectName());
        for (int i = 0; i < orderProjects.size(); i++) {
            int i1 = returnerMapper.deleteOrder(orderProjects.get(i).getOrderId());
        }
        returnerMapper.deleteOrderProject(project.getProjectName());
        returnerMapper.deleteReturner(projectId);
        return 1;
    }
}
